from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from time import sleep
from appium.webdriver.common.mobileby import MobileBy
from faker import Faker
faker = Faker(locale='zh_cn')
phone = str(faker.phone_number())
cap_dict = {
    "platformName":"Android",
    "platformVersion":"7.1.2",
    "deviceName":"x1q",
    "appPackage":"com.threegene.doctor",
    "appActivity":".module.splash.SplashActivity"
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",cap_dict)
driver.implicitly_wait(15)
# 点击同意，用tap
sleep(3)
TouchAction(driver).tap(x = 462 , y = 1119).perform()
# 使用轻扫进行滑动页面：第一次
sleep(2)
driver.swipe(861,1364,46,1373)
# 使用轻扫进行滑动页面：第二次
sleep(2)
driver.swipe(861,1364,46,1373)
# 点击立即体验
driver.find_element(MobileBy.ID,"com.threegene.doctor:id/submit_btn").click()
# 点击已阅读
driver.find_element(MobileBy.CLASS_NAME,"android.widget.CompoundButton").click()
# 点击手机号登录
driver.find_element(MobileBy.ID,"com.threegene.doctor:id/tv_phone_login").click()
# 输入手机号
driver.find_element(MobileBy.ID,"com.threegene.doctor:id/edit_phone_number").send_keys(phone)
# 点击获取验证码
driver.find_element(MobileBy.ID,"com.threegene.doctor:id/tv_send_code").click()
# 断言
text = driver.find_element(MobileBy.ID,"com.threegene.doctor:id/sms_send_hint").text

assert phone[-4:] in text
# test = "15948557896"
# print(test[-4:])

